-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Fix unfinished step in parallel flow #4567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix unfinished step in parallel flow #4567
Conversation
f101e58
to
b8a1ba8
Compare
} | ||
} | ||
} | ||
|
||
if (!exceptions.isEmpty()) { | ||
throw exceptions.get(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As before, the first caught exception would be thrown.
jobBuilder.preventRestart().build().execute(execution); | ||
|
||
boolean isExecutedNonExecutableStep = countDownLatch.await(1, TimeUnit.SECONDS); | ||
assertEquals(BatchStatus.STOPPED, execution.getStatus()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finished with BatchStatus.STOPPED
without executing nonExecutableStep
.
This test would fail with executing nonExecutableStep
if it runs on the current main branch.
Gentle ping to @fmbenhassine. Could you review this PR? I've fixed #3939. |
Thank you for your PR!
Isn't that not desired when one of the tasks is interrupted? Meaning if one wants to interrupt a step, the idea is not to wait for other steps to finish. The change in this PR fixes the reported issue, I just want to make sure there is no side effect on the behaviour of step interruption. |
Thank you for the comment! And sorry for the late reply. @fmbenhassine I've also thought about your concern. And I don't think this change of exception handling location affects the current process of handling interruptions in steps, so has no side effect. spring-batch/spring-batch-core/src/main/java/org/springframework/batch/core/step/AbstractStep.java Line 230 in 425134c
Interruption only can be recognized in catch or final blocks after doExecute has been done.
Therefore, even if interrupt occurs in a step, other steps process its executions until the end and check interruptions from other steps regardless of my modification. In the virtue of my modification, other steps can recognize the interruptions because job is not STOPPED yet. The difference is that the current code immediately propagates the exception generated by interrupt and terminates the job ( Lines 287 to 294 in 425134c
and continue to be executed with STOPPED status of their parent job. It is a cause of the bug. In conclusion, there is no change from the view of steps, because in the current code the step execution is also not stopped even if an exception caused by interrupt occurs in another step. Interrupt is caught after step execution has been done. And I think So I think my changes will prevent other unknown bugs that can occur as flow and step continue to run with job stopped. Sorry for the lengthy explanation. if you have any other opinions, please leave a comment for more discussions. Thank you! |
Gentle remind @fmbenhassine. Could you check this PR? |
Thank you for your feedback! I saw your comment back then and added a thumbs-up emoji and the Thank you for going into details with your last update! I love how you explained the step interruption process and how this change should not have a side effect 👍 |
Rebased and merged as 7678949. Thank you for your contribution! |
related issue #3939
Motivation
https://github.com/spring-projects/spring-batch/blob/9a2b1bbc96f338017aaa5df51214896f5a32d1e5/spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java#L290C16-L290C17
Because the job already had been terminated and in STOPPED status, a step in the other flow cannot recognize it and proceeded as like there had been no interruption.
Modification
Result